﻿$(document).on("pageInit", "#apply-detail-teacher", function (e, id, page) {
    $.getJSON("/apply/GetApplyById/" + $(page).find('[name="id"]').val(), function (response) {
        var statusEnum = {
            2: "审批中",
            3: "已拒绝",
            4: "已通过"
        };

        if (response.Status != 2) {
            $(page).find("#btn-list").hide();
            $(page).find('.approve-form').hide();
            //$(page).find('[name=ApproveRemark]').prop("disabled", true);
        } else {
            $(page).find('.approve-item').hide();
        }
        response.Status = statusEnum[response.Status]
        $(page).setForm(response);
    });

    $(page).find("#btn-agree").on("click", function (evt) {
        evt.preventDefault();
        var app =$(page).find("input[name=ApproveRemark]").val();
        utils.$postJson({
            ApproveStatus: 4,
            id: $(page).find("input[name=id]").val(),
            ApproveRemark: app
        }, "/Apply/Approve", function (response) {
            if (response.indexOf("err:") > -1) {
                $.toast(response.substr(4));
                return false;
            }
            $.toast("保存成功！");
            history.back();
        });
    });

    $(page).find("#btn-reject").on("click", function (evt) {
        evt.preventDefault();

        utils.$postJson({
            ApproveStatus: 3,
            id: $(page).find("[name=id]").val(),
            ApproveRemark: $(page).find("[name=ApproveRemark]").val()
        }, "/Apply/Approve", function (response) {
            if (response.indexOf("err:") > -1) {
                $.toast(response.substr(4));
                return false;
            }
            $.toast("保存成功！");
            history.back();
        });
    });
});